package vlcjdemo;

public final class Tests {

    private Tests() {
    }

    /**
     * Ensures that an object reference passed as a parameter to the calling
     * method is not null.
     *
     * @param reference an object reference
     * @return the non-null reference that was validated
     * @throws NullPointerException if {@code reference} is null
     */
    public static <T> T checkNotNull(T reference) {
        if (reference == null) {
            throw new NullPointerException();
        }
        return reference;
    }

    /**
     * Ensures that an object reference passed as a parameter to the calling
     * method is not null.
     *
     * @param reference an object reference
     * @param errorMessage the exception message to use if the check fails; will
     *     be converted to a string using {@link String#valueOf(Object)}
     * @return the non-null reference that was validated
     * @throws NullPointerException if {@code reference} is null
     */
    public static <T> T checkNotNull(T reference, Object errorMessage) {
        if (reference == null) {
            throw new NullPointerException(String.valueOf(errorMessage));
        }
        return reference;
    }

    /**
     * A workaround for the mis-design of the AssertionError exception
     * (no msg + cause constructor).
     * @param msg
     * @param cause
     */
    public static AssertionError assertionError(String msg, Throwable cause) {
        AssertionError error = new AssertionError(msg);
        error.initCause(cause);
        return error;
    }

    /**
     * Checks if all ints are different
     * @param ints
     * @return true if all ints are different, false otherwise
     */
    public static boolean allDifferent(int... ints) {
        int counter = 0;
        for (int i : ints) {
            counter = 0;
            for (int e : ints) {
                if (i == e) {
                    counter++;
                }
            }
            if (counter != 1) {
                return false;
            }
        }
        return true;
    }
}
